package com.alumni_circle.controller.me;

import com.alumni_circle.core.config.SysLog;
import com.alumni_circle.core.entity.BaseId;
import com.alumni_circle.core.entity.PageBase;
import com.alumni_circle.core.entity.ResponseListModel;
import com.alumni_circle.core.entity.ResponseModel;
import com.alumni_circle.core.utils.ModelUtils;
import com.alumni_circle.core.utils.SecurityUtils;
import com.alumni_circle.core.web.BaseController;
import com.alumni_circle.entity.me.FeedBack;
import com.alumni_circle.entity.me.VO.FeedBackInsertVO;
import com.alumni_circle.entity.me.VO.FeedBackUpdateVO;
import com.alumni_circle.service.me.impl.FeedBackServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 龙小虬
 * @since 2020-07-06 22:58
 */
@Api(tags = "反馈信息")
@Controller
@RequestMapping("/feedBack")
public class FeedBackController extends BaseController<FeedBack> {

    @Resource
    private FeedBackServiceImpl feedBackService;


    /**
     * 增加、更新用户信息
     *
     * @param feedBackInsertVO
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/addFeedBack", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "新增反馈信息", notes = "增加反馈信息", httpMethod = "POST", response = ResponseModel.class)
    @SysLog(type="增",accessInfo="新增反馈信息",url="/feedBack/addFeedBack")
    public ResponseModel addFeedBack(@ApiParam(required = true, name = "feedBackInsertVO")
                                 @RequestBody FeedBackInsertVO feedBackInsertVO) {
        feedBackInsertVO.setName(SecurityUtils.getId());
        feedBackService.save(ModelUtils.transform(feedBackInsertVO,FeedBack.class));
        return null;
    }


    @ResponseBody
    @RequestMapping(value = "/updateFeedBack", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "更新反馈信息", notes = "更新反馈信息", httpMethod = "POST", response = ResponseModel.class)
    @SysLog(type="改",accessInfo="更新反馈信息",url="/feedBack/updateFeedBack")
    public ResponseModel updateFeedBack(@ApiParam(required = true, name = "feedBackUpdateVO")
                                        @RequestBody FeedBackUpdateVO feedBackUpdateVO) {
        feedBackService.updateById(ModelUtils.transform(feedBackUpdateVO,FeedBack.class));
        return null;
    }

    @ResponseBody
    @RequestMapping(value = "/delFeedBack", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "删除反馈信息", notes = "删除反馈信息", httpMethod = "POST", response = ResponseModel.class)
    @SysLog(type="删",accessInfo="删除反馈信息",url="/feedBack/delFeedBack")
    public ResponseModel 删除反馈信息(@ApiParam(required = true, name = "feedBackUpdateVO")
                                    @RequestBody BaseId baseId) {
        feedBackService.removeById(baseId.getId());
        return null;
    }

    @ResponseBody
    @RequestMapping(value = "/getAllFeedBack", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "查询反馈信息", notes = "查询反馈信息", httpMethod = "POST", response = ResponseModel.class)
    @SysLog(type="查",accessInfo="查询反馈信息",url="/feedBack/getAllFeedBack")
    public ResponseListModel getAllUser(@ApiParam(required = true, name = "pageBase")
                                        @RequestBody PageBase pageBase) {
        PageHelper.startPage(pageBase.getPageNum(),pageBase.getPageSize());
        List<FeedBack > list = feedBackService.list();
        PageInfo<FeedBack> pageInfo = new PageInfo<>(list);
        return new ResponseListModel<>(list,String.valueOf(pageInfo.getTotal()));
    }

}